#include <stdio.h>
#define N 1000
int an[N+1];

int main_17()
{
    int n,cnt=0;
    scanf("%d",&n);
    for (int i=0;i<n ;i++ )
    {
        scanf("%d",&an[i]);
    }
    for (int i=1;i<n-1 ;i++ )
    {
        if ((an[i]>an[i-1]&&an[i]>an[i+1])||(an[i]<an[i-1]&&an[i]<an[i+1]))
        {
            cnt++;
        }
    }
    printf("%d\n",cnt);
	return 0;
}
